//
//  BMUtils.m
//  IphoneMapSdkDemo
//
//  Created by huck on 2017/5/30.
//  Copyright © 2017年 Baidu. All rights reserved.
// 百度地图工具

#import "BMUtils.h"
#import "AppUtils.h"
//#import "BNCoreServices.h"

@implementation BMUtils

+(CLLocationCoordinate2D)getPoint:(NSString *)pointStr
{
    @try {
        CLLocationCoordinate2D mapCentre;
        NSArray *pointArr = [pointStr componentsSeparatedByString:@","];
        mapCentre.longitude = [AppUtils toString:pointArr[0]].doubleValue;
        mapCentre.latitude = [AppUtils toString:pointArr[1]].doubleValue;
        return mapCentre;
    } @catch (NSException *exception) {
        NSLog(@"生成百度点坐标的时候数据错误了");
    }
}


+(BOOL)canMakePoint:(NSString *)pointStr
{
    BOOL flag = NO;
    if([AppUtils isNotEmpty:pointStr]){
        NSArray *pointArr = [pointStr componentsSeparatedByString:@","];
        if(pointArr!=nil && pointArr.count ==2){
            flag = YES;
        }
    }
    return flag;
}
//
//+ (BMKAnnotationView *)createCustomAnnotationView:(BMKMapView *)mapView image:(NSString *)imageName size:(CGSize)imageFrame
//{
//    NSString *AnnotationViewID = @"AnimatedAnnotation";
//    BMKAnnotationView *annotationView = (BMKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
//    if (annotationView == nil) {
//        annotationView = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
//        [annotationView setBounds:CGRectMake(0.f, 0.f, 20.f, 20.f)];
//        [annotationView setBackgroundColor:[UIColor clearColor]];
//        UIImageView *icon = [[UIImageView alloc] initWithFrame:annotationView.bounds];
//        icon.tag = 100;
//        [annotationView addSubview:icon];
//        icon.contentMode = UIViewContentModeScaleToFill;
//    }
//    UIImageView *icon = [annotationView viewWithTag:100];
//    icon.image = [UIImage imageNamed: isDirect ? @"bad_water_river_yes":@"bad_water_river_no"];
//    return annotationView;
//}

//打开客户端直接导航
+ (void)openNativeNavi:(CLLocationCoordinate2D)startLocation endLocation:(CLLocationCoordinate2D)endLocation endName:(NSString *)endName
{
    //初始化调启导航时的参数管理类
    BMKNaviPara* para = [[BMKNaviPara alloc]init];
    //初始化起点节点
    BMKPlanNode* start = [[BMKPlanNode alloc]init];
    //指定起点经纬度
    start.pt = startLocation;
    //指定起点名称
    start.name = @"我的位置";
    //指定起点
    para.startPoint = start;
    
    //初始化终点节点
    BMKPlanNode* end = [[BMKPlanNode alloc]init];
    //指定终点经纬度
    end.pt =endLocation;
    //指定终点名称
    if([AppUtils isEmpty:endName]){
        endName =@"终点";
    }
    end.name = endName;
    //指定终点
    para.endPoint = end;
    
    //指定返回自定义scheme
    para.appScheme =  MAP_URL_SCHEME;
    
    //调启百度地图客户端导航
    [BMKNavigation openBaiduMapNavigation:para];
}

//打开地图 驾车路线检索
+ (void)openMapDrivingRoute:(CLLocationCoordinate2D)startLocation endLocation:(CLLocationCoordinate2D)endLocation endName:(NSString *)endName
{
    BMKOpenDrivingRouteOption *opt = [[BMKOpenDrivingRouteOption alloc] init];
    //    opt.appName = @"SDK调起Demo";
    opt.appScheme = MAP_URL_SCHEME;
    //初始化起点节点
    BMKPlanNode* start = [[BMKPlanNode alloc]init];
    //指定起点经纬度
    start.pt = startLocation;
    //指定起点名称
    start.name = @"我的位置";
    //指定起点
    opt.startPoint = start;
    
    //初始化终点节点
    BMKPlanNode* end = [[BMKPlanNode alloc]init];
    end.pt = endLocation;
    //指定终点名称
    end.name = endName;
    opt.endPoint = end;
    BMKOpenErrorCode code = [BMKOpenRoute openBaiduMapDrivingRoute:opt];
    NSLog(@"%d", code);
    return;
}

+(BOOL)hasinitialMapApp
{
    return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]];

}
//
//+(CLLocationCoordinate2D )getMyLocation
//{
//    return  [BNCoreServices_Location getLastLocation].coordinate;
//}



@end
